<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="postList">
      <el-table-column width="70" type="index" label="序号" align="center" />
      <el-table-column label="车站名称" align="center" prop="stationName" />
      <el-table-column label="是否售票" align="center" prop="isallow">
        <template slot-scope="scope">
          <p v-if="postList[scope.$index].isallow == 0">否</p>
          <p v-if="postList[scope.$index].isallow == 1">售</p>
        </template>
      </el-table-column>
      <el-table-column label="车站编号" align="center" prop="globalcode" />
      <el-table-column label="未取车票" align="center" prop="useableTickets" />
      <el-table-column label="时间" align="center" prop="updatetime">
        <template slot-scope="scope">
          <span>{{ newDate(scope.row.lastTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="错误原因"
        align="center"
        prop="errorMsg"
        width="500"
      >
        <template slot-scope="scope">
          <p>
            {{ scope.row.errorMsg }}
            <a href="#" style="color:blue" @click="getParticulars(scope.row)"
              >详情</a
            >
          </p>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 错误详情 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form :model="form" label-width="80px">
        <el-row>
          <el-col :span="18">
            <el-form-item label="错误原因:" label-width="115px">
              <div>{{ err }}</div>

              <!-- <el-input v-model="form.machinecode" :disabled="true" /> -->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="详情:" label-width="115px">
              <div>{{ form.messageContent }}</div>
              <!-- <el-input v-model="form.jobnum" placeholder="请输入" /> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="open = false">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { status, getBusinfoLog } from "@/api/operationLog/stationErro";
import utils from "../../js/index";

export default {
  name: "StationErro",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      allocation: {
        machinecode: "",
        qph: "",
        zph: "",
        dqph: ""
      },
      // 查询参数
      queryParams: {
        pageIndex: 1,
        pageSize: 10,
        stt: "error",
        errormsg: undefined,
        machinecode: undefined
      },
      // 详情信息
      form: {},
      err: ""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车站报错列表 */
    getList() {
      status(this.queryParams).then(response => {
        if (response.code == 200) {
          this.postList = response.data.pageInfo;
          this.total = response.data.error;
          this.loading = false;
        } else {
          this.$message.error(response.msg);
        }
      });
    },
    // 格式化时间
    newDate(date) {
      return utils.utils.NewDate(date);
    },
    getClear(row) {
      cleanError({ machinecode: row.machinecode, id: row.id }).then(
        response => {
          if (response.code == 200) {
            this.getList();
          } else {
            this.$message.error(response.msg);
          }
        }
      );
    },
    // 获取错误详情
    getParticulars(val) {
      const loading = this.$loading({
          lock: true,
          text: '获取数据中...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      this.err = val.errorMsg;
      this.title = "查看错误原因";
      getBusinfoLog({ globalcode: val.globalcode }).then(response => {
        if (response.code == 200) {
          loading.close();
          this.open = true;
          this.form = response.data;
        } else {
          loading.close();
          this.$message.error(response.msg);
        }
      });
    }
  }
};
</script>
